home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / Tasks / TaskBSemaphore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-07  |  1.6 KB  |  76 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <powerup/ppclib/interface.h>
  6. #include <powerup/ppclib/semaphore.h>
  7. #include <powerup/gcclib/powerup_protos.h>
  8.  
  9. #define    SEMAPHORENAME    "TaskSemaphore"
  10.  
  11. int    main(void)
  12. {
  13. BPTR        MyFile;
  14. ULONG        MySignal;
  15. void        *Semaphore;
  16. BOOL        MySemaphore;
  17. BOOL        ObtainedByName;
  18. struct TagItem    MyTags[10];
  19. int        i;
  20.  
  21.   MySemaphore        =    FALSE;
  22.   ObtainedByName    =    TRUE;
  23.   if ((Semaphore=PPCObtainSemaphoreByName(SEMAPHORENAME))==NULL)
  24.   {
  25.     MyTags[0].ti_Tag    =    PPCSEMAPHORETAG_NAME;
  26.     MyTags[0].ti_Data    =    (ULONG) SEMAPHORENAME;
  27.     MyTags[1].ti_Tag    =    TAG_DONE;
  28.     if ((Semaphore=PPCCreateSemaphore(MyTags))==NULL)
  29.     {
  30.       if ((Semaphore=PPCObtainSemaphoreByName(SEMAPHORENAME))==NULL)
  31.       {
  32.         /*
  33.          * CreateSemaphore didn`t work and that wasn`t caused by a parallel TaskB
  34.          * running
  35.          */
  36.         PPCprintf("Can`t obtain semaphore from task A or create my own\n");
  37.         return(20);
  38.       }
  39.     }
  40.     else
  41.     {
  42.       MySemaphore    =    TRUE;
  43.       ObtainedByName    =    FALSE;
  44.     }
  45.   }
  46.  
  47.   if (MyFile=PPCOpen("con:0/200/640/200/TaskB/CLOSE",MODE_NEWFILE))
  48.   {
  49.     for (;;)
  50.     {
  51.       if (!ObtainedByName)
  52.       {
  53.         PPCObtainSemaphore(Semaphore);
  54.       }
  55.       for (i=0;i<10;i++)
  56.       {
  57.         PPCfprintf(MyFile,
  58.                    "%ld:Task A is active\n",
  59.                    i);
  60.       }
  61.       PPCReleaseSemaphore(Semaphore);
  62.       ObtainedByName    =    FALSE;
  63.     }
  64.     PPCClose(MyFile);
  65.   }
  66.   else
  67.   {
  68.     PPCprintf("Couldn`t open CLI Window\n");
  69.   }
  70.   if (MySemaphore)
  71.   {
  72.     PPCDeleteSemaphore(Semaphore);
  73.   }
  74.   return(0);
  75. }
  76.